/**
    Copyright (c) 2010 yakiimo02
    Distributed under the New BSD License.
    See included license.txt or http://www.yakiimo3d.com/NewBSDLicense.txt
**/

/**
    @file   
    @brief   Blend prev frame with current frame.
    @author  yakiimo02
    @date    2010/09/26
*/

struct QuadVS_Input
{
    float4 Pos : POSITION;
    float2 Tex : TEXCOORD0;
};

struct QuadVS_Output
{
    float4 Pos : SV_POSITION;              
    float2 Tex : TEXCOORD0;
};

/** Vertex Shader */

QuadVS_Output QuadVS( QuadVS_Input Input )
{
    QuadVS_Output Output;
    Output.Pos = Input.Pos;
    Output.Tex = Input.Tex;
    return Output;
}

/** Pixel Shader */

Texture2D    sceneTexPrev : register( t0 );
Texture2D    sceneTexCur  : register( t1 );

SamplerState        PointSampler : register (s0);

cbuffer cbPS : register( b0 )
{
    float4    g_param;                        // x,y are input buffer width height   
                                              // z is antialiasing type (need to match enum AAMode in TemporalAA.h)
};

float4 QuadPS( QuadVS_Output Input ) : SV_TARGET
{
    float4 vColor = float4( 1.0f, 1.0f, 1.0f, 1.0f );

    if( g_param.z == 0 || g_param.z == 1 || g_param.z == 2 )
    {
        vColor = sceneTexCur.Sample( PointSampler, Input.Tex );
    }
    else if( g_param.z == 3 )
    {
        vColor = ( sceneTexPrev.Sample( PointSampler, Input.Tex ) + sceneTexCur.Sample( PointSampler, Input.Tex ) ) * 0.5f;        
    }

    return vColor;
}